<?php
class Members extends MY_Controller{
	
	function __construct(){
		parent::__construct();
		if(!$this->admin) redirect('admin990/login');
	}
	
	function index()
	{
		$data['title'] = "Clients";
		$data['admin'] = $this->admin;
		$data['members'] = member::find('all',array('limit'=>'','offset'=>'','order'=>'id desc'));	
		$this->config->load('pagination');
		$config['per_page'] = 10; 
		$config['uri_segment'] = 3;
		$config['num_links'] = 4;
	 	$config['base_url'] = site_url('admin990/members/');
		$config['total_rows'] = count($data['members']);
		$config['enable_query_strings']=true;
		$this->pagination->initialize($config); 
		$data['num'] = count($data['members']);
	 	$data['page_links']= $this->pagination->create_links();
	 	$data['members'] = member::find('all', array('limit' => $config['per_page'], 'offset' =>$this->uri->segment(3),'order'=>'id desc'));
	 	
		$this->load->view('admin/header',$data);
		$this->load->view('admin/members/index');
		
		
	}
	
	function orders()
	{
		$member_id = $this->uri->segment(4);
		$data['title'] = "Commandes du client";
		$data['admin'] = $this->admin;
		$data['this_member'] = member::find_by_id($member_id);
		$data['orders'] = order::find('all',array('conditions'=>'member_id='.$member_id));
		$this->load->view('admin/header',$data);
		$this->load->view('admin/members/orders');
		
	}
	
	function status()
	{
		if($_POST)
		{	
			if($_POST['status']=='null'){$status=null;}else{$status=$_POST['status']; }
			$member_status = member::find_by_id($_POST['id']);
			$member_status->status = $status;
			if($member_status->save()){
			echo json_encode(true);
			}else{
			echo json_encode(false);
			}
			
		}	
	}
	
	
}